let redis = require("../util/redisDB")
const util = require('../util/common')

function navMenu(req, res, next) {
    let key = req.headers.fapp + ":nav_menu"
    const data = [
        {
            name: "主页",
            src:"http://loaclhost"
        },
        {
            name: "文章",
            src:"/article/list"
        }
    ]
    const serializedArray = JSON.stringify(data);
    // 获取数据
    redis.set(key, serializedArray)
}

const footer = (req, res, next) => { 
    let key = req.headers.fapp + ":footer"
    const data = [
        {
            name: "版权所有",
            src: "http://loaclhost",
            text: "Stiller"
        },
        {
            name: "发送邮件",
            src: "mailto:uneedzf@gmail.com",
            text: "Gmail"
        }
        
    ]
    const serializedArray = JSON.stringify(data);
    // 获取数据
    redis.set(key, serializedArray)
}

const links = (req, res, next) => { 
    let key = req.headers.fapp + ":links"
    const data = [
        {
            name: "baidu",
            src: "http://baidu.com"
        }
        
    ]
    const serializedArray = JSON.stringify(data);
    // 获取数据
    redis.set(key, serializedArray)
}

const indexPic = (req, res, next) => { 
    let key = req.headers.fapp + ":indexPic"
    const data = [
        {
            title: "baidu",
            src: "http://baidu.com",
            img: "http://218.60.94.17:18082/image/supervision/default.png"
        }
        
    ]
    const serializedArray = JSON.stringify(data);
    // 获取数据
    redis.set(key, serializedArray)
}

// const hotArticle = (req, res, next) => { 
//     let key = req.headers.fapp + ":a_view"
//     const data = [
//         {
//             title: "文章暂未上线",
//             date: "",
//             id: 0,
//             view: 0
//         },
//         {
//             title: "测试文字3",
//             date: "2020-11-22 16:56:43",
//             id: 4,
//             view: '1'
//         }
        
//     ]
//     const serializedArray = JSON.stringify(data);
//     // 获取数据
//     redis.set(key, serializedArray)
// }

exports.setData = (req, res, next) => {
    navMenu(req, res, next)
    footer(req, res, next)
    links(req, res, next)
    indexPic(req, res, next)
    // hotArticle(req, res, next)
    res.json(util.getReturnData(0,'添加成功'))
}